/** 
 * Project Name:kaka 
 * File Name:CardAction.java 
 * Package Name:com.luoran.kaka.action 
 * Date:2018年12月5日上午11:06:55 
 * Copyright (c) 2018, Luoran, Inc. All Rights Reserved.
 * 
 */  
package com.luoran.kaka.action;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.luoran.kaka.entity.BasicInfo;
import com.luoran.kaka.entity.CompanyInfo;
import com.luoran.kaka.service.IBasicInfoService;
import com.luoran.kaka.service.ICompanyInfoService;

/** 
 * ClassName: CardAction
 * date: 2018年12月5日 上午11:06:55
 * @author ghl 
 * @since JDK 1.8
 */
@Controller
@RequestMapping("/card")
public class CardAction {
	
	private static final Logger log = LoggerFactory.getLogger(CardAction.class);
	
	@Autowired
	private IBasicInfoService basicInfoService;
	
	@Autowired
	private ICompanyInfoService companyInfoService;

	/** 
	 * 
	 * @author ghl 2018年12月7日下午3:58:33
	 * @param openId
	 * @param model
	 * @return 
	 * @since JDK 1.8
	 * myCard:进入我的主页
	 */ 
	@RequestMapping("/my/{openId}")
	public String myCard(@PathVariable("openId")String openId,Model model) {
//		openId = "o91QW1o0MtQakWin1jq-2GD-pnmo";
		log.info("当前用户的openid为：{}",openId);
		model.addAttribute("openId", openId);
		return "my/card";
	}
	
	
	
	/** 
	 * 
	 * @author ghl 2018年12月7日下午4:00:14
	 * @param openId
	 * @return 
	 * @since JDK 1.8
	 * getAllMyPersonalCard:获取我的所有个人名片
	 */ 
	@RequestMapping("/my/personal/{openId}")
	@ResponseBody
	public JSONObject getAllMyPersonalCard(@PathVariable("openId")String openId) {
		log.info("获取当前用户所有的个人名片，参数openId为：{{}}",openId);
		JSONObject obj = new JSONObject();
		List<BasicInfo> list = basicInfoService.getAllMyPersonalCardByOpenId(openId);
		if(null!=list && list.size()>0) {
			obj.put("flag", true);
			obj.put("list", list);
			return obj;
		}else {
			obj.put("flag", false);
			obj.put("msg", "没有个人名片，点击添加。");
			return obj;
		}
	}
	
	
	/** 
	 * 
	 * @author ghl 2018年12月7日下午4:00:37
	 * @param openId
	 * @return 
	 * @since JDK 1.8
	 * getAllMyCompanyCard:获取我的所有企业名片
	 */ 
	@RequestMapping("/my/company/{openId}")
	@ResponseBody
	public JSONObject getAllMyCompanyCard(@PathVariable("openId")String openId) {
		log.info("获取当前用户所有的企业名片，参数openId为：{{}}",openId);
		JSONObject obj = new JSONObject();
		List<CompanyInfo> list = companyInfoService.getAllMyCompanyCardByOpenId(openId);
		if(null!=list && list.size()>0) {
			obj.put("flag", true);
			obj.put("list", list);
			return obj;
		}else {
			obj.put("flag", false);
			obj.put("msg", "没有企业名片，点击添加。");
			return obj;
		}
	}
	
}
